package com.xunyoutest.shop.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

/**
 * Created by admin on 2018/3/2.
 */

public class JsonParseUtils {
    private static JsonParseUtils instance;
    private static String mJson = "";
    private static JSONObject object;

    public static JsonParseUtils getInstance(String json) {
        if (instance == null) {
            instance = new JsonParseUtils();
        }
        if (!mJson.equals(json)) {
            object = JSON.parseObject(json);
            mJson = json;
        }
        return instance;
    }

    public JsonParseUtils() {

    }

    public JSONObject getObject(){
        return object;
    }

    /**
     * 返回状态
     * @return
     */
    public boolean parseStatus() {
        String status = object.getString("status");
        return status.equals("200");
    }

    /**
     * 返回状态码
     * @return
     */
    public String parseStatusStr() {
        return object.getString("status");
    }

    /**
     * 返回错误信息
     * @return
     */
    public String parseMsg() {
        return object.getString("msg");
    }

    /**
     * 返回Json内容
     * @return
     */
    public JSONObject parseData() {
        return object.getJSONObject("data");
    }
}
